package com.example.restatr.Atcivity.YouthInn;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.example.restatr.Atcivity.YouthInn.Bean.YouthInnInfoBean;
import com.example.restatr.R;
import com.example.restatr.Tools;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

public class YouthInnInfoAt extends AppCompatActivity {

    private YouthInnInfoBean.DataBean rowsBean;
    private Toolbar toolbar;
    private TextView barTitle;
    private EditText search;
    private ImageView head;
    private TextView name;
    private TextView phone;
    private TextView bedsCountBoy;
    private TextView bedsCountGirl;
    private TextView address;
    private TextView workTime;
    private TextView introduce;
    private TextView internalFacilities;
    private TextView surroundingFacilities;
    private TextView specialService;
    private RecyclerView rv;
    private List<String> imageUrlList=new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info_at);
        bindView();
        rowsBean = new Gson().fromJson(getIntent().getStringExtra("data"), YouthInnInfoBean.class).getData();
        Tools.SetBarTitle(toolbar, barTitle, "驿站详情", search, this, false);

        Glide.with(this)
                .load(Tools.ip + rowsBean.getCoverImgUrl())
                .transform(new RoundedCorners(15))
                .into(head);
        name.setText(rowsBean.getName());
        phone.setText(rowsBean.getPhone());
        bedsCountBoy.setText(rowsBean.getBedsCountBoy() + "个/男");
        bedsCountGirl.setText(rowsBean.getBedsCountBoy() + "个/女");
        address.setText(rowsBean.getAddress());
        workTime.setText(rowsBean.getWorkTime());
        introduce.setText(rowsBean.getIntroduce());
        internalFacilities.setText(rowsBean.getInternalFacilities());
        surroundingFacilities.setText(rowsBean.getSurroundingFacilities());
        specialService.setText(rowsBean.getSpecialService());
        rv.setAdapter(new adapter());
        imageUrlList = rowsBean.getImageUrlList();
    }

    private void bindView() {
        toolbar = findViewById(R.id.toolbar);
        barTitle = findViewById(R.id.bar_Title);
        search = findViewById(R.id.search);
        head = findViewById(R.id.head);
        name = findViewById(R.id.name);
        phone = findViewById(R.id.phone);
        bedsCountBoy = findViewById(R.id.bedsCountBoy);
        bedsCountGirl = findViewById(R.id.bedsCountGirl);
        address = findViewById(R.id.address);
        workTime = findViewById(R.id.workTime);
        introduce = findViewById(R.id.introduce);
        internalFacilities = findViewById(R.id.internalFacilities);
        surroundingFacilities = findViewById(R.id.surroundingFacilities);
        specialService = findViewById(R.id.specialService);
        rv = findViewById(R.id.rv);
    }

    class adapter extends RecyclerView.Adapter<adapter.viewHolder> {

        @NonNull
        @Override
        public viewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View inflate = getLayoutInflater().inflate(R.layout.img_layout, parent, false);
            return new viewHolder(inflate);
        }

        @Override
        public void onBindViewHolder(@NonNull viewHolder holder, int position) {
            Glide.with(YouthInnInfoAt.this)
                    .load(Tools.ip + imageUrlList.get(position))
                    .transform(new RoundedCorners(15))
                    .into(holder.img);
        }

        @Override
        public int getItemCount() {
            return imageUrlList.size();
        }

        class viewHolder extends RecyclerView.ViewHolder {
            private ImageView img;

            public viewHolder(@NonNull View itemView) {
                super(itemView);
                img = itemView.findViewById(R.id.img);
            }
        }
    }

}